{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "eb0ae49a-1c5f-4949-b073-13a39825b002",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "PostgreSQL版本: ('(openGauss-lite 5.0.3 build 89d144c2) compiled at 2024-07-31 21:39:16 commit 0 last mr  release',)\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "from core.database import DatabaseManager\n",
    "\n",
    "current_path = os.path.abspath('.')\n",
    "pg_manager=DatabaseManager(current_path+\"/config.yaml\")\n",
    "pg_manager.set_provider('opengauss')\n",
    "conn = pg_manager.connect()\n",
    "# 使用连接执行查询\n",
    "with conn.cursor() as cursor:\n",
    "    cursor.execute(\"SELECT version()\")\n",
    "    print(\"PostgreSQL版本:\", cursor.fetchone())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "b098cd88-af5f-421b-96ec-1fda168286ad",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(150, 6)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Id</th>\n",
       "      <th>SepalLengthCm</th>\n",
       "      <th>SepalWidthCm</th>\n",
       "      <th>PetalLengthCm</th>\n",
       "      <th>PetalWidthCm</th>\n",
       "      <th>Species</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>5.1</td>\n",
       "      <td>3.5</td>\n",
       "      <td>1.4</td>\n",
       "      <td>0.2</td>\n",
       "      <td>Iris-setosa</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>4.9</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.4</td>\n",
       "      <td>0.2</td>\n",
       "      <td>Iris-setosa</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>4.7</td>\n",
       "      <td>3.2</td>\n",
       "      <td>1.3</td>\n",
       "      <td>0.2</td>\n",
       "      <td>Iris-setosa</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>4.6</td>\n",
       "      <td>3.1</td>\n",
       "      <td>1.5</td>\n",
       "      <td>0.2</td>\n",
       "      <td>Iris-setosa</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>5.0</td>\n",
       "      <td>3.6</td>\n",
       "      <td>1.4</td>\n",
       "      <td>0.2</td>\n",
       "      <td>Iris-setosa</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>145</th>\n",
       "      <td>146</td>\n",
       "      <td>6.7</td>\n",
       "      <td>3.0</td>\n",
       "      <td>5.2</td>\n",
       "      <td>2.3</td>\n",
       "      <td>Iris-virginica</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>146</th>\n",
       "      <td>147</td>\n",
       "      <td>6.3</td>\n",
       "      <td>2.5</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.9</td>\n",
       "      <td>Iris-virginica</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>147</th>\n",
       "      <td>148</td>\n",
       "      <td>6.5</td>\n",
       "      <td>3.0</td>\n",
       "      <td>5.2</td>\n",
       "      <td>2.0</td>\n",
       "      <td>Iris-virginica</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>148</th>\n",
       "      <td>149</td>\n",
       "      <td>6.2</td>\n",
       "      <td>3.4</td>\n",
       "      <td>5.4</td>\n",
       "      <td>2.3</td>\n",
       "      <td>Iris-virginica</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149</th>\n",
       "      <td>150</td>\n",
       "      <td>5.9</td>\n",
       "      <td>3.0</td>\n",
       "      <td>5.1</td>\n",
       "      <td>1.8</td>\n",
       "      <td>Iris-virginica</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>150 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      Id  SepalLengthCm  SepalWidthCm  PetalLengthCm  PetalWidthCm  \\\n",
       "0      1            5.1           3.5            1.4           0.2   \n",
       "1      2            4.9           3.0            1.4           0.2   \n",
       "2      3            4.7           3.2            1.3           0.2   \n",
       "3      4            4.6           3.1            1.5           0.2   \n",
       "4      5            5.0           3.6            1.4           0.2   \n",
       "..   ...            ...           ...            ...           ...   \n",
       "145  146            6.7           3.0            5.2           2.3   \n",
       "146  147            6.3           2.5            5.0           1.9   \n",
       "147  148            6.5           3.0            5.2           2.0   \n",
       "148  149            6.2           3.4            5.4           2.3   \n",
       "149  150            5.9           3.0            5.1           1.8   \n",
       "\n",
       "            Species  \n",
       "0       Iris-setosa  \n",
       "1       Iris-setosa  \n",
       "2       Iris-setosa  \n",
       "3       Iris-setosa  \n",
       "4       Iris-setosa  \n",
       "..              ...  \n",
       "145  Iris-virginica  \n",
       "146  Iris-virginica  \n",
       "147  Iris-virginica  \n",
       "148  Iris-virginica  \n",
       "149  Iris-virginica  \n",
       "\n",
       "[150 rows x 6 columns]"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn import svm\n",
    "# 从CSV文件读取鸢尾花数据集\n",
    "iris = pd.read_csv(current_path+'/../data/Iris.csv')\n",
    "# 查看数据集大小\n",
    "print(iris.shape)\n",
    "# 将数据集划分为训练集和测试集，测试集占总数据的20%\n",
    "train, test = train_test_split(iris, test_size=0.4)\n",
    "iris\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "f05be55d-b053-41ae-b979-81e555177ccb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "60"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 存储训练和测试数据到Postgres数据库\n",
    "engine=pg_manager.create_engine()\n",
    "train.to_sql(\"iris_train\", engine, if_exists='replace', index=False)\n",
    "#test.columns = [col.lower() for col in test.columns]\n",
    "test.to_sql(\"iris_test\", engine, if_exists='replace', index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "61156d3d-31dc-4218-abba-10b2b49171b9",
   "metadata": {},
   "outputs": [],
   "source": [
    "# openGuass svm_classification\n",
    "# svm_classification\n",
    "conn=pg_manager.connect()\n",
    "from psycopg2.extensions import connection\n",
    "def create(conn: connection):\n",
    "    cur = conn.cursor()\n",
    "    cur.execute(\"DROP MODEL iris_svm_model;\")\n",
    "    #cur.execute('CREATE MODEL iris_svm_model USING logistic_regression FEATURES sepal_length, sepal_width,petal_length TARGET petal_width<1 FROM iris;')\n",
    "    cur.execute('CREATE MODEL iris_svm_model USING svm_classification FEATURES \"SepalLengthCm\", \"SepalWidthCm\", \"PetalLengthCm\", \"PetalWidthCm\" TARGET \"PetalWidthCm\"<=2.5 FROM iris_train;')\n",
    "\n",
    "create(conn)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "344c1a92-da16-4312-b151-d1ce1b417735",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "modelname: [('iris_svm_model',)]\n"
     ]
    }
   ],
   "source": [
    "def get_modelname(conn: connection):\n",
    "    cur = conn.cursor()\n",
    "    cur.execute(\"SELECT modelname from gs_model_warehouse where modelname='iris_svm_model';\")\n",
    "    results=cur.fetchall()\n",
    "    print(\"modelname: %s\" %(results))\n",
    "get_modelname(pg_manager.connect())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "9f7a59c5-08dc-4408-972c-92348188ecb5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "predict result: [('Iris-setosa', True), ('Iris-versicolor', True), ('Iris-virginica', True), ('Iris-setosa', True), ('Iris-versicolor', True), ('Iris-versicolor', True), ('Iris-virginica', True), ('Iris-setosa', True), ('Iris-setosa', True), ('Iris-setosa', True), ('Iris-setosa', True), ('Iris-virginica', True), ('Iris-setosa', True), ('Iris-setosa', True), ('Iris-versicolor', True), ('Iris-virginica', True), ('Iris-setosa', True), ('Iris-versicolor', True), ('Iris-virginica', True), ('Iris-versicolor', True), ('Iris-virginica', True), ('Iris-virginica', True), ('Iris-virginica', True), ('Iris-virginica', True), ('Iris-versicolor', True), ('Iris-virginica', True), ('Iris-setosa', True), ('Iris-virginica', True), ('Iris-setosa', True), ('Iris-virginica', True), ('Iris-setosa', True), ('Iris-versicolor', True), ('Iris-versicolor', True), ('Iris-virginica', True), ('Iris-versicolor', True), ('Iris-setosa', True), ('Iris-versicolor', True), ('Iris-setosa', True), ('Iris-setosa', True), ('Iris-versicolor', True), ('Iris-setosa', True), ('Iris-setosa', True), ('Iris-virginica', True), ('Iris-virginica', True), ('Iris-versicolor', True), ('Iris-setosa', True), ('Iris-setosa', True), ('Iris-versicolor', True), ('Iris-virginica', True), ('Iris-setosa', True), ('Iris-setosa', True), ('Iris-virginica', True), ('Iris-virginica', True), ('Iris-virginica', True), ('Iris-virginica', True), ('Iris-setosa', True), ('Iris-versicolor', True), ('Iris-setosa', True), ('Iris-setosa', True), ('Iris-versicolor', True)]\n"
     ]
    }
   ],
   "source": [
    "def predict(conn: connection):\n",
    "    cur = conn.cursor()\n",
    "    cur.execute('SELECT \"Species\", PREDICT BY iris_svm_model (FEATURES \"SepalLengthCm\", \"SepalWidthCm\", \"PetalLengthCm\", \"PetalWidthCm\"  ) as \"PREDICT\" FROM iris_test;')\n",
    "    results=cur.fetchall()\n",
    "    print(\"predict result: %s\" % (results))\n",
    "predict(conn)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "1a714c7c-6221-40f5-a503-1f4803141b81",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>SepalLengthCm</th>\n",
       "      <th>SepalWidthCm</th>\n",
       "      <th>PetalLengthCm</th>\n",
       "      <th>PetalWidthCm</th>\n",
       "      <th>Species</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Id</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>139</th>\n",
       "      <td>6.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>4.8</td>\n",
       "      <td>1.8</td>\n",
       "      <td>Iris-virginica</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>143</th>\n",
       "      <td>5.8</td>\n",
       "      <td>2.7</td>\n",
       "      <td>5.1</td>\n",
       "      <td>1.9</td>\n",
       "      <td>Iris-virginica</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>89</th>\n",
       "      <td>5.6</td>\n",
       "      <td>3.0</td>\n",
       "      <td>4.1</td>\n",
       "      <td>1.3</td>\n",
       "      <td>Iris-versicolor</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61</th>\n",
       "      <td>5.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>3.5</td>\n",
       "      <td>1.0</td>\n",
       "      <td>Iris-versicolor</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>116</th>\n",
       "      <td>6.4</td>\n",
       "      <td>3.2</td>\n",
       "      <td>5.3</td>\n",
       "      <td>2.3</td>\n",
       "      <td>Iris-virginica</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>5.4</td>\n",
       "      <td>3.9</td>\n",
       "      <td>1.3</td>\n",
       "      <td>0.4</td>\n",
       "      <td>Iris-setosa</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>4.8</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.4</td>\n",
       "      <td>0.1</td>\n",
       "      <td>Iris-setosa</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>129</th>\n",
       "      <td>6.4</td>\n",
       "      <td>2.8</td>\n",
       "      <td>5.6</td>\n",
       "      <td>2.1</td>\n",
       "      <td>Iris-virginica</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>4.3</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.1</td>\n",
       "      <td>0.1</td>\n",
       "      <td>Iris-setosa</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4.7</td>\n",
       "      <td>3.2</td>\n",
       "      <td>1.3</td>\n",
       "      <td>0.2</td>\n",
       "      <td>Iris-setosa</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>120 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     SepalLengthCm  SepalWidthCm  PetalLengthCm  PetalWidthCm          Species\n",
       "Id                                                                            \n",
       "139            6.0           3.0            4.8           1.8   Iris-virginica\n",
       "143            5.8           2.7            5.1           1.9   Iris-virginica\n",
       "89             5.6           3.0            4.1           1.3  Iris-versicolor\n",
       "61             5.0           2.0            3.5           1.0  Iris-versicolor\n",
       "116            6.4           3.2            5.3           2.3   Iris-virginica\n",
       "..             ...           ...            ...           ...              ...\n",
       "17             5.4           3.9            1.3           0.4      Iris-setosa\n",
       "13             4.8           3.0            1.4           0.1      Iris-setosa\n",
       "129            6.4           2.8            5.6           2.1   Iris-virginica\n",
       "14             4.3           3.0            1.1           0.1      Iris-setosa\n",
       "3              4.7           3.2            1.3           0.2      Iris-setosa\n",
       "\n",
       "[120 rows x 5 columns]"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "engine=pg_manager.create_engine()\n",
    "data=pd.read_sql('''SELECT * FROM  iris_train;''', con = engine,index_col=\"Id\")\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "id": "24ff582e-d6a4-4207-9173-8f36b921b712",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[LibSVM]*\n",
      "optimization finished, #iter = 16\n",
      "obj = -0.748057, rho = -1.452044\n",
      "nSV = 3, nBSV = 0\n",
      "*\n",
      "optimization finished, #iter = 5\n",
      "obj = -0.203684, rho = -1.507091\n",
      "nSV = 3, nBSV = 0\n",
      "*\n",
      "optimization finished, #iter = 33\n",
      "obj = -13.730499, rho = -8.624603\n",
      "nSV = 20, nBSV = 16\n",
      "Total nSV = 24\n",
      "The accuracy of the SVM is: 0.9777777777777777\n",
      "0.022222222222222254\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn import svm\n",
    "from sklearn import metrics\n",
    "\n",
    "\n",
    "train, test = train_test_split(iris, test_size=0.3)\n",
    "# 提取训练集和测试集的特征和标签\n",
    "train_x = train[['SepalLengthCm', 'SepalWidthCm', 'PetalLengthCm', 'PetalWidthCm']]\n",
    "train_y = train.Species\n",
    "test_x = test[['SepalLengthCm', 'SepalWidthCm', 'PetalLengthCm', 'PetalWidthCm']]\n",
    "test_y = test.Species\n",
    "\n",
    "# 创建支持向量机（SVM）分类器模型\n",
    "# openGuass 默认SVM kernel函数为linear，其支持linear/gaussian/polynomial 核函数\n",
    "# SVC默认kernel函数为RBF(即gaussian核函数)\n",
    "# just for linear、SVM：kernel = \"linear\" linear/gaussian/polynomial 核函数\n",
    "model = svm.SVC(verbose=1, kernel='linear')\n",
    "# 在训练集上拟合SVM模型\n",
    "model.fit(train_x, train_y)\n",
    "# 使用训练好的模型对测试集进行预测\n",
    "prediction = model.predict(test_x)\n",
    "# 打印SVM模型的准确性\n",
    "print('The accuracy of the SVM is:', metrics.accuracy_score(prediction, test_y))\n",
    "\n",
    "\n",
    "print(metrics.zero_one_loss(test_y, prediction))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "id": "5fb6acf6-9fc0-42f2-b567-38a20b2ac573",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 True Iris-versicolor Iris-versicolor\n",
      "1 True Iris-setosa Iris-setosa\n",
      "2 True Iris-virginica Iris-virginica\n",
      "3 True Iris-versicolor Iris-versicolor\n",
      "4 True Iris-versicolor Iris-versicolor\n",
      "5 True Iris-setosa Iris-setosa\n",
      "6 True Iris-setosa Iris-setosa\n",
      "7 True Iris-versicolor Iris-versicolor\n",
      "8 True Iris-versicolor Iris-versicolor\n",
      "9 True Iris-versicolor Iris-versicolor\n",
      "10 True Iris-versicolor Iris-versicolor\n",
      "11 True Iris-versicolor Iris-versicolor\n",
      "12 True Iris-setosa Iris-setosa\n",
      "13 True Iris-setosa Iris-setosa\n",
      "14 True Iris-setosa Iris-setosa\n",
      "15 True Iris-virginica Iris-virginica\n",
      "16 True Iris-virginica Iris-virginica\n",
      "17 True Iris-setosa Iris-setosa\n",
      "18 True Iris-setosa Iris-setosa\n",
      "19 True Iris-virginica Iris-virginica\n",
      "20 True Iris-versicolor Iris-versicolor\n",
      "21 True Iris-setosa Iris-setosa\n",
      "22 True Iris-versicolor Iris-versicolor\n",
      "23 True Iris-virginica Iris-virginica\n",
      "24 True Iris-virginica Iris-virginica\n",
      "25 True Iris-virginica Iris-virginica\n",
      "26 True Iris-setosa Iris-setosa\n",
      "27 True Iris-versicolor Iris-versicolor\n",
      "28 True Iris-setosa Iris-setosa\n",
      "29 True Iris-virginica Iris-virginica\n",
      "30 True Iris-setosa Iris-setosa\n",
      "31 True Iris-versicolor Iris-versicolor\n",
      "32 True Iris-setosa Iris-setosa\n",
      "33 True Iris-virginica Iris-virginica\n",
      "34 True Iris-virginica Iris-virginica\n",
      "35 True Iris-versicolor Iris-versicolor\n",
      "36 True Iris-virginica Iris-virginica\n",
      "37 True Iris-setosa Iris-setosa\n",
      "38 True Iris-versicolor Iris-versicolor\n",
      "39 True Iris-virginica Iris-virginica\n",
      "40 True Iris-versicolor Iris-versicolor\n",
      "41 False Iris-versicolor Iris-virginica\n",
      "42 True Iris-setosa Iris-setosa\n",
      "43 True Iris-virginica Iris-virginica\n",
      "44 True Iris-virginica Iris-virginica\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "def check_prediction(prediction: np.ndarray, test: pd.DataFrame):\n",
    "    raw=test.Species.tolist()\n",
    "    cnt=0\n",
    "    for idx, specie in enumerate(raw):\n",
    "        is_euqal=False\n",
    "        if  prediction[idx]==specie:\n",
    "            is_euqal=True\n",
    "        else:\n",
    "            cnt+=1\n",
    "        print(idx,is_euqal, specie, prediction[idx])\n",
    "    return cnt\n",
    "cnt=check_prediction(prediction, test)\n",
    "cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "df7c0453-b053-4a47-b5b6-f333b8018943",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
